
#pragma once

#include "VertexBuffer.h"
#include "glm\glm.hpp"
#include "glm\ext.hpp"
using namespace glm;


class Mesh
{
public:
	Mesh(VertexBuffer* vertexBuffer);

	VertexBufferDescr& getVertexBufferDescr() { return _vertexBeffer->getVertexBufferDescr(); }
	char* getDataWithAttribId(int attribId) { return _vertexBeffer->getDataWithAttribId(attribId) ;}

	const mat4& getModelMatrix();

public:
	VertexBuffer* _vertexBeffer;
	mat4 _modelMatrix;
	vec3 _position;
	vec3 _rotation;
};


Mesh::Mesh(VertexBuffer* vertexBuffer)
{
	assert(vertexBuffer != nullptr);

	_vertexBeffer = vertexBuffer;
	_modelMatrix = mat4();
	_position = vec3(0.0f, 0.0f, 0.0f);
	_rotation = vec3(0.0f, 0.0f, 0.0f);
}

const mat4& Mesh::getModelMatrix()
{
	_modelMatrix = translate(mat4(1.0f), _position.x, _position.y, _position.z);
	_modelMatrix = rotate(_modelMatrix, _rotation.z, vec3(0.0f, 0.0f, 1.0f));
	_modelMatrix = rotate(_modelMatrix, _rotation.y, vec3(0.0f, 1.0f, 0.0f));
	_modelMatrix = rotate(_modelMatrix, _rotation.x, vec3(1.0f, 0.0f, 0.0f));

	return _modelMatrix;
}